//
//  RGMessageFuncCell.m
//  RedGrass
//
//  Created by wukong on 2018/11/25.
//  Copyright © 2018年 hongcaosp. All rights reserved.
//

#import "RGMessageFuncCell.h"
#import "RGMessageFuncItem.h"
#import "RGMessageModel.h"
@interface RGMessageFuncCell()

@property (strong, nonatomic) UILabel *topLine;
@property (strong, nonatomic) UILabel *bottomLine;
@property (strong, nonatomic) RGMessageFuncItem *item1;
@property (strong, nonatomic) RGMessageFuncItem *item2;
@property (strong, nonatomic) RGMessageFuncItem *item3;
@property (strong, nonatomic) RGMessageFuncItem *item4;

@property (assign, nonatomic) CGFloat itemWidth;
@property (assign, nonatomic) CGFloat itemOffsetY;
@property (assign, nonatomic) CGFloat baseOffsetY;


@end

@implementation RGMessageFuncCell

-(instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        self.contentView.backgroundColor = [UIColor blackColor];
        [self setSelectionStyle:UITableViewCellSelectionStyleNone];
        _itemWidth = 55;
        _baseOffsetY = 15;
        _itemOffsetY = (KScreenWidth - 15 * 2 - 55 * 4) / 3;
        [self initUI];
        [self addMasonry];
    }
    return self;
}

- (void)setModel:(RGMessageModel *)model {
    _model = model;
    
}

-(void)initUI{
    [self.contentView addSubview:self.topLine];
    [self.contentView addSubview:self.item1];
    [self.contentView addSubview:self.item2];
    [self.contentView addSubview:self.item3];
    [self.contentView addSubview:self.item4];
    [self.contentView addSubview:self.bottomLine];
}

-(void) addMasonry{
    [_topLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.mas_equalTo(self.contentView).mas_offset(0);
        make.top.mas_equalTo(self.contentView).mas_offset(0);
        make.height.mas_equalTo(0.5);
    }];
    
    [_bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView).mas_offset(15);
        make.right.mas_equalTo(self.contentView).mas_offset(-15);
        make.bottom.mas_equalTo(self.contentView).mas_offset(0);
        make.height.mas_equalTo(0.5);
    }];
    
    [_item1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(55, 75));
        make.left.mas_equalTo(self.contentView).mas_offset(15);
        make.centerY.mas_equalTo(self.contentView).mas_offset(0);
    }];
    
    [_item2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(55, 75));
        make.left.mas_equalTo(self.contentView).mas_offset(15 + (55 + self.itemOffsetY)*1);
        make.centerY.mas_equalTo(self.contentView).mas_offset(0);
    }];
    
    [_item3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(55, 75));
        make.left.mas_equalTo(self.contentView).mas_offset(15 + (55 + self.itemOffsetY)*2);
        make.centerY.mas_equalTo(self.contentView).mas_offset(0);
    }];
    
    [_item4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(55, 75));
        make.left.mas_equalTo(self.contentView).mas_offset(15 + (55 + self.itemOffsetY)*3);
        make.centerY.mas_equalTo(self.contentView).mas_offset(0);
    }];
}

- (void)addAction {
    if (self.actionBtnClick) {
        AA_WEAK_MAKE(self) weakSelf = self;
        [_item1 setActionBtnClick:^(NSInteger tag) {
            weakSelf.actionBtnClick(10000);
        }];
        
        [_item2 setActionBtnClick:^(NSInteger tag) {
            weakSelf.actionBtnClick(10001);
        }];
        
        [_item3 setActionBtnClick:^(NSInteger tag) {
            weakSelf.actionBtnClick(10002);
        }];
        
        [_item4 setActionBtnClick:^(NSInteger tag) {
            weakSelf.actionBtnClick(10003);
        }];
    }
}


#pragma mark -getter

-(UILabel *)topLine{
    if(!_topLine){
        _topLine = [[UILabel alloc]init];
        _topLine.backgroundColor = UICOLOR_WITH_RGBINT(0xe5e5e5);
    }
    return _topLine;
}

-(UILabel *)bottomLine{
    if(!_bottomLine){
        _bottomLine = [[UILabel alloc]init];
        _bottomLine.backgroundColor = UICOLOR_WITH_RGBINT(0xe5e5e5);
    }
    return _bottomLine;
}

-(RGMessageFuncItem *)item1{
    if(!_item1){
        _item1 = [RGMessageFuncItem initRGMessageFuncItemWithIcon:@"粉丝" title:@"粉丝"];
        _item1.tag = 10000;
    }
    return _item1;
}

-(RGMessageFuncItem *)item2{
    if(!_item2){
        _item2 = [RGMessageFuncItem initRGMessageFuncItemWithIcon:@"赞" title:@"赞"];
        _item2.tag = 10001;
    }
    return _item2;
}
-(RGMessageFuncItem *)item3{
    if(!_item3){
        _item3 = [RGMessageFuncItem initRGMessageFuncItemWithIcon:@"@我的" title:@"@我的"];
        _item3.tag = 10002;
    }
    return _item3;
}
-(RGMessageFuncItem *)item4{
    if(!_item4){
        _item4 = [RGMessageFuncItem initRGMessageFuncItemWithIcon:@"评论" title:@"评论"];
        _item4.tag = 10003;
    }
    return _item4;
}


@end
